package com.techshine.service.impl;

import javax.annotation.Resource;
import java.util.List;
import org.springframework.stereotype.Service;

import com.techshine.service.EquService;
import com.techshine.util.StringUtil;
import com.techshine.entity.Constant;
import com.techshine.entity.Equ;
import com.techshine.mapper.EquMapper;

 
/** 
 * 说明： 设备
 * 
 */
@Service
public class EquServiceImpl implements EquService {
	
	@Resource
	private EquMapper equMapper;
	@Override
	public Equ queryByKey(String id)throws Exception{
		return equMapper.queryByKey(id);
	}
	@Override
	public List<Equ> queryListByPage(Equ entity)throws Exception{
		return equMapper.queryListByPage(entity);
	}
	@Override
	public List<Equ> queryList(Equ entity)throws Exception{
		return equMapper.queryList(entity);
	}
	@Override
	public void insert(Equ entity)throws Exception{
		equMapper.insert(entity);
	}
	@Override
	public void insertSelective(Equ entity)throws Exception{
		String imgurls = entity.getImgurl();
		if(StringUtil.isNotEmpty(imgurls)) {
			String[] split = imgurls.split(",");
			for(String imgurl:split) {
				entity.setId(null);
				entity.setImgurl(imgurl);
				equMapper.insertSelective(entity);
			}
		}
		 
	}
	@Override
	public void update(Equ entity)throws Exception{
	 	equMapper.update(entity);
	}
	@Override
	public void updateByKeySelective(Equ entity)throws Exception{
		 equMapper.updateByKeySelective(entity);
	}
	public void delete(Equ entity)throws Exception{
		 equMapper.delete(entity);
	}
	@Override
	public void delmore(String ids) throws Exception {
		// TODO Auto-generated method stub
		String[] split = ids.split(",");
		Equ node=new Equ();
		for(String id:split) {
			try {
				node.setId(Integer.parseInt(id));
				equMapper.delete(node);
			}catch (Exception e) {
				// TODO: handle exception
			}
		}
	}
	@Override
	public void updatestas(String ids,String category) throws Exception {
		// TODO Auto-generated method stub
		String[] split = ids.split(",");
		Equ equ=new Equ();
		for(String id:split) {
			try {
				equ.setId(Integer.parseInt(id));
				equ.setCategory(category);
				equMapper.updateByKeySelective(equ);
			}catch (Exception e) {
				// TODO: handle exception
			}
			
		}
	}
	
}

